// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------
// Modification history:
// feature: support agent between domain
// feature: provide query interfaces
// feature: develop dispatcher
// feature: discovery support client and server
// ------------------------------------------------------------------

#include <history/CacheChange.h>
#include <edds/rtps/common/Guid.h>

#include <discovery/database/DiscoveryParticipantChangeData.hpp>
#include <discovery/database/DiscoveryEndpointInfo.hpp>

namespace evbs {
namespace ertps {
namespace rtps {
namespace ddb {

class DiscoveryDataQueueInfo {
 public:
    DiscoveryDataQueueInfo(CacheChange_t* change) : change_(change) {}

    ~DiscoveryDataQueueInfo() {}

    CacheChange_t* change() { return change_; }

 protected:
    CacheChange_t* change_;
};

class DiscoveryPDPDataQueueInfo : public DiscoveryDataQueueInfo {
 public:
    DiscoveryPDPDataQueueInfo(CacheChange_t* change, const DiscoveryParticipantChangeData& participant_change_data)
        : DiscoveryDataQueueInfo(change), participant_change_data_(participant_change_data) {}

    ~DiscoveryPDPDataQueueInfo() {}

    DiscoveryParticipantChangeData participant_change_data() const { return participant_change_data_; }

 private:
    DiscoveryParticipantChangeData participant_change_data_;
};

class DiscoveryEDPDataQueueInfo : public DiscoveryDataQueueInfo {
 public:
    DiscoveryEDPDataQueueInfo(CacheChange_t* change, const string_255& topic, const vbsutil::xmlparser::ReaderQos& qos,
                              const string_255& type_name = "", bool take_locator = false, uint32_t queue_id = 0)
        : DiscoveryDataQueueInfo(change),
          topic_(topic),
          type_name_(type_name),
          qos_(qos),
          take_locator_(take_locator),
          dsf_queue_id(queue_id) {
        is_writer = false;
    }
    DiscoveryEDPDataQueueInfo(CacheChange_t* change, const string_255& topic, const vbsutil::xmlparser::WriterQos& qos,
                              const string_255& type_name = "", bool take_locator = false)
        : DiscoveryDataQueueInfo(change), topic_(topic), type_name_(type_name), qos_(qos), take_locator_(take_locator) {
        is_writer = true;
        dsf_queue_id = 0;
    }

    DiscoveryEDPDataQueueInfo(const DiscoveryEDPDataQueueInfo& other)
        : DiscoveryDataQueueInfo(other.change_),
          topic_(other.topic_),
          type_name_(other.type_name_),
          is_writer(other.is_writer),
          qos_(other.qos_),
          take_locator_(other.take_locator_),
          dsf_queue_id(other.dsf_queue_id) {}
    ~DiscoveryEDPDataQueueInfo() {}

    string_255 topic() { return topic_; }

    string_255 type_name() { return type_name_; }

    EndpointQos qos() { return qos_; }

    bool take_locator() { return take_locator_; }

    uint32_t get_queue_id() { return dsf_queue_id; }

 private:
    const string_255 topic_;
    const string_255 type_name_;
    bool is_writer;
    EndpointQos qos_;
    bool take_locator_;
    uint32_t dsf_queue_id;
};

} /* namespace ddb */
}  // namespace rtps
} /* namespace ertps */
} /* namespace evbs */
